<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>background-size背景尺寸</title>
  <style>
    div {
      float:left;
      margin:20px;
      width:50px;
      height:50px;
    }
    /* px  %  cover contain auto

    cover: 会等比例放大 并且超出的部分会被裁剪
    contain: container也会拉伸,但只要一个方位达到容器的边缘就会停止拉伸,不会出现裁剪,但会出现留白的情况（So常常和center连用

    容器比例 =  图片素材比例 ---> cover
    容器比例 !=  图片素材比例 ---> contain
    --- --- ---
    background-size ---> px/%
    Using both a width and a height value,
    in which case the first sets the width and the second sets the height.
    Each value can be a <length>, a <percentage>, or auto.
    */
    .box1{
      /*background:url(images/icon-wechat.png);*/
      background:#000 url(../images/icon-wechat.png) no-repeat center/*水平*/ center/*垂直*/;
      background-size: 20px 20px;
    }
    .box2{
      background:#000 url(../images/icon-rp.png) no-repeat center;
      background-size: contain;
    }
    .box3{
      background:#000 url(../images/icon-credit.png) no-repeat center;
      background-size: contain;
    }
  </style>
</head>

<body>

<div class="box1"></div>

<div class="box2"></div>

<div class="box3"></div>

<div class="box4"></div>
<br>
<div class="box5"></div>

</body>

</html>
